/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qltieuhoc;

import bll.DsNamHocBll;
import bll.LopBll;
import javax.swing.table.TableModel;
import bll.HocSinhBll;
import bll.StudentModel;
import java.awt.Color;
import java.util.ArrayList;
import object.DsLop;
import object.NamHoc;
import object.Lop;
import object.DsNamHoc;
import object.Student;

/**
 *
 * @author Le Thai
 */
public class FormQLHocSinh extends javax.swing.JInternalFrame {

    /**
     * Creates new form FormQLHocSinh
     */
    private int maNamHoc;
    private DsNamHoc dsNam = new DsNamHoc();
    private DsLop dsLop = new DsLop();

    public FormQLHocSinh() {
        initComponents();
        this.ResultTable.getTableHeader().setReorderingAllowed(false);
        napDsNamHoc();
        napDsLopHoc(maNamHoc);
        ResultTable.setModel(new StudentModel(new ArrayList<Student>()));
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        ResultTable = new javax.swing.JTable();
        btnSearch = new javax.swing.JButton();
        txtKeyword = new javax.swing.JTextField();
        cbTimTheoLop = new javax.swing.JComboBox();
        chxLocTheoLop = new javax.swing.JCheckBox();
        cbNamHoc = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        txtDiaChi = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cbLop = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        txtHoDem = new javax.swing.JTextField();
        btnThem = new java.awt.Button();
        jLabel4 = new javax.swing.JLabel();
        btnXoa = new java.awt.Button();
        txtNgaySinh = new javax.swing.JTextField();
        cbGioiTinh = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtTen = new javax.swing.JTextField();
        btnCapNhat = new java.awt.Button();
        lbStatus = new java.awt.Label();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Quản Lý Học Sinh");
        setPreferredSize(new java.awt.Dimension(800, 600));

        ResultTable.setAutoCreateRowSorter(true);
        ResultTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        ResultTable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        ResultTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                ResultTableMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(ResultTable);

        btnSearch.setText("Tìm");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        chxLocTheoLop.setText("Thuộc lớp");

        cbNamHoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbNamHocActionPerformed(evt);
            }
        });

        jLabel8.setText("Năm học:");

        jLabel6.setText("Lớp");

        jLabel3.setText("Ngày sinh");

        btnThem.setLabel("Thêm");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        jLabel4.setText("Giới tính");

        btnXoa.setLabel("Xoá");
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });

        cbGioiTinh.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nữ", "Nam" }));

        jLabel5.setText("Địa chỉ");
        jLabel5.setToolTipText("");

        jLabel1.setText("Họ đệm");

        jLabel2.setText("Tên");

        btnCapNhat.setLabel("Cập nhật");
        btnCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCapNhatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbLop, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(txtHoDem, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(btnThem, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(25, 25, 25)
                                .addComponent(btnCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbGioiTinh, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtHoDem, txtNgaySinh});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel1))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtHoDem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(cbGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(cbLop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnThem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 47, Short.MAX_VALUE))
        );

        btnXoa.getAccessibleContext().setAccessibleName("");

        lbStatus.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        lbStatus.setName(""); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addComponent(txtKeyword, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnSearch)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbNamHoc, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(chxLocTheoLop)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbTimTheoLop, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(250, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtKeyword, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cbNamHoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8)))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbTimTheoLop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chxLocTheoLop))
                .addGap(2, 2, 2)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lbStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    //nap danh sach nam hoc

    private void napDsNamHoc() {
        DsNamHocBll dsNamBll = new DsNamHocBll();
        dsNam = dsNamBll.layDsNamHoc();
        for (NamHoc nh : dsNam.getDsNamHoc()) {
            cbNamHoc.addItem(nh.getTenNh());
            cbNamHoc.setSelectedItem(nh.getTenNh());
            maNamHoc = nh.getMaNh();

        }
    }

    //nap danh sach cac lop
    private void napDsLopHoc(int maNh) {
        LopBll lopBll = new LopBll();
        dsLop = lopBll.layDsLop(maNh);
        for (Lop l : dsLop.getDsLop()) {
            cbTimTheoLop.addItem(l.getLop());
            cbLop.addItem(l.getLop());
        }
    }

    //dinh dang bang
    private void formatTable() {
        this.ResultTable.getColumnModel().getColumn(0).setPreferredWidth(50);
        this.ResultTable.getColumnModel().getColumn(1).setPreferredWidth(120);
        this.ResultTable.getColumnModel().getColumn(2).setPreferredWidth(70);
        this.ResultTable.getColumnModel().getColumn(3).setPreferredWidth(50);
        this.ResultTable.getColumnModel().getColumn(4).setPreferredWidth(100);
        this.ResultTable.getColumnModel().getColumn(5).setPreferredWidth(200);
        this.ResultTable.getColumnModel().getColumn(5).setPreferredWidth(100);

    }

    // action nut tim kiem
    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        // TODO add your handling code here:
        timHocSinh();
    }//GEN-LAST:event_btnSearchActionPerformed
    //tim hoc sinh
    private void timHocSinh(){
         HocSinhBll hsBll = new HocSinhBll();
        TableModel tbModel;

        int maLop;
        if (chxLocTheoLop.isSelected()) {
            maLop = dsLop.timMaLop(cbTimTheoLop.getSelectedItem().toString());
        } else {
            maLop = 0;
        }

        int maNh = dsNam.timMaNamHoc(cbNamHoc.getSelectedItem().toString());

        tbModel = hsBll.timHocSinh(txtKeyword.getText(), maLop, maNh);
        lbStatus.setForeground(Color.BLUE);
        ResultTable.setModel(tbModel);
        lbStatus.setText("Tìm được: " + ResultTable.getRowCount() + " kết quả");
        formatTable();
    
    }
    //action nut them hoc sinh
    private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
        // TODO add your handling code here:
        if (txtHoDem.getText().equals("") || txtTen.getText().equals("")) {
            lbStatus.setForeground(Color.red);
            lbStatus.setText("Bạn chưa nhập đầy đủ họ tên!");
        } else {
            HocSinhBll hsBll = new HocSinhBll();
            boolean gender = cbGioiTinh.getSelectedIndex() == 1 ? true : false;
            int malop = dsLop.timMaLop(cbLop.getSelectedItem().toString());
            int id = hsBll.themHocSinh(txtHoDem.getText(), txtTen.getText(), gender, txtNgaySinh.getText(), txtDiaChi.getText(), malop);
            if (id > 0) {
                lbStatus.setForeground(Color.BLUE);
                lbStatus.setText("đã thêm học sinh mã số " + id);
                ResultTable.setModel(hsBll.timTheoMaHs(id, maNamHoc));
                ResultTable.repaint();
                
            } else {
                lbStatus.setForeground(Color.red);
                lbStatus.setText("không thể thêm thông tin này");
            }
        }
    }//GEN-LAST:event_btnThemActionPerformed
    //lay gia tri dong hien tai khi nhan su kien tha chuot
    private void ResultTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ResultTableMouseReleased
        // TODO add your handling code here:
        if(ResultTable.getModel().getRowCount()>0){
            int rowSelectedIndex = ResultTable.getSelectedRow();
            String tmp = String.valueOf(ResultTable.getValueAt(rowSelectedIndex, 1));
            txtHoDem.setText(tmp);
            tmp = String.valueOf(ResultTable.getValueAt(rowSelectedIndex, 2));
            txtTen.setText(tmp);
            boolean gender = (boolean) ResultTable.getValueAt(rowSelectedIndex, 3);
            cbGioiTinh.setSelectedIndex(gender ? 1 : 0);
            tmp = String.valueOf(ResultTable.getValueAt(rowSelectedIndex, 4));
            txtNgaySinh.setText(tmp);
            tmp = String.valueOf(ResultTable.getValueAt(rowSelectedIndex, 5));
            txtDiaChi.setText(tmp);
            tmp = String.valueOf(ResultTable.getValueAt(rowSelectedIndex, 6));
            int n = cbLop.getItemCount();
            for (int i = 0; i < n; i++) {
                if (tmp.equals(cbLop.getItemAt(i))) {
                    cbLop.setSelectedIndex(i);
                    break;
                }
            }
        }
    }//GEN-LAST:event_ResultTableMouseReleased

    private void btnCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCapNhatActionPerformed
        // TODO add your handling code here:
        if (txtHoDem.getText().equals("") || txtTen.getText().equals("")) {
            lbStatus.setForeground(Color.red);
            lbStatus.setText("Bạn chưa nhập đầy đủ họ tên!");
        }else{
            HocSinhBll hsBll=new HocSinhBll();
            int rowIndex=ResultTable.getSelectedRow();
            int maHs=Integer.parseInt(ResultTable.getModel().getValueAt(rowIndex, 0).toString());
            int malop = dsLop.timMaLop(cbLop.getSelectedItem().toString());
            boolean gender = cbGioiTinh.getSelectedIndex() == 1 ? true : false;
            boolean isSuccess=hsBll.capNhatHosSinh(maHs,txtHoDem.getText(), 
                    txtTen.getText(), gender, txtNgaySinh.getText(), txtDiaChi.getText(), malop);
            if(isSuccess){
                lbStatus.setForeground(Color.BLUE);
                lbStatus.setText("Đã cập nhật thông tin");
                ResultTable.setModel(hsBll.timTheoMaHs(maHs, maNamHoc));
                ResultTable.repaint();
            }else{
                lbStatus.setForeground(Color.RED);
                lbStatus.setText("Không thể cập nhật thông tin");
            }
        }
        
        
    }//GEN-LAST:event_btnCapNhatActionPerformed
    //xoa hoc sinh
    private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
        // TODO add your handling code here:
        HocSinhBll hsBll = new HocSinhBll();
        if(ResultTable.getModel().getRowCount()==0){
            lbStatus.setForeground(Color.RED);
            lbStatus.setText("Không có dữ liệu để xoá");
        
        }
        else{
            int rowIndex = ResultTable.getSelectedRow();
            if (rowIndex == -1) {
                lbStatus.setForeground(Color.RED);
                lbStatus.setText("Bạn chưa chọn dòng sẽ xoá");
            } else {
                int maHs = Integer.parseInt(ResultTable.getValueAt(rowIndex, 0).toString());
                if (hsBll.xoaHocSinh(maHs)) {
                    lbStatus.setForeground(Color.BLUE);
                    lbStatus.setText("Đã xoá học sinh mã số " + maHs);
                    ((StudentModel) ResultTable.getModel()).removeRowAt(rowIndex);
                    ResultTable.repaint();
                } else {
                    lbStatus.setForeground(Color.RED);
                    lbStatus.setText("Xoá không thành công");
                }

            }
        }

    }//GEN-LAST:event_btnXoaActionPerformed

    private void cbNamHocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbNamHocActionPerformed
        // TODO add your handling code here:
        int maNamHoc=dsNam.timMaNamHoc(cbNamHoc.getSelectedItem().toString());
        napDsLopHoc(maNamHoc);
    }//GEN-LAST:event_cbNamHocActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable ResultTable;
    private java.awt.Button btnCapNhat;
    private javax.swing.JButton btnSearch;
    private java.awt.Button btnThem;
    private java.awt.Button btnXoa;
    private javax.swing.JComboBox cbGioiTinh;
    private javax.swing.JComboBox cbLop;
    private javax.swing.JComboBox cbNamHoc;
    private javax.swing.JComboBox cbTimTheoLop;
    private javax.swing.JCheckBox chxLocTheoLop;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private java.awt.Label lbStatus;
    private javax.swing.JTextField txtDiaChi;
    private javax.swing.JTextField txtHoDem;
    private javax.swing.JTextField txtKeyword;
    private javax.swing.JTextField txtNgaySinh;
    private javax.swing.JTextField txtTen;
    // End of variables declaration//GEN-END:variables
}
